package com.skynet.supervision.utils;

import lombok.SneakyThrows;
import lombok.val;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public abstract class IO {

    public static void copy(OutputStream dst, InputStream src) {
        copy(dst, src, null);
    }

    @SneakyThrows(IOException.class)
    public static void copy(OutputStream os, InputStream is, byte[] buffer) {
        if (buffer == null) {
            buffer = new byte[1024 * 1024 * 4];
        }
        for (; ; ) {
            val nRead = is.read(buffer);
            if (nRead == -1) {
                break;
            }
            os.write(buffer, 0, nRead);
        }
    }

}
